import redis
import pymysql.cursors
import postman
import time


def redis_drop():
    db0 = redis.Redis('192.168.190.128', db=0)
    db1 = redis.Redis('192.168.190.128', db=1)
    db2 = redis.Redis('192.168.190.128', db=2)

    db0.flushdb()
    db1.flushdb()
    db2.flushdb()


def mysql_drop():
    connection = pymysql.connect(host='192.168.190.128',
                                 user='xhm',
                                 password='159180',
                                 db='todolist',
                                 cursorclass=pymysql.cursors.DictCursor)
    try:
        with connection.cursor() as cursor:
            # Create a new record
            sql1 = "DELETE FROM ip_table WHERE id;"
            sql2 = "DELETE FROM user WHERE id;"
            cursor.execute(sql1)
            cursor.execute(sql2)

            # connection is not autocommit by default. So you must commit to save
            # your changes.
            connection.commit()
    finally:
        connection.close()


if __name__ == '__main__':
    redis_drop()
    mysql_drop()
    time.sleep(1.5)
    url = "/users/reg"
    postman.post(url)
